<template>
<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="120px" style="margin:10px 10px;">
  <el-form-item label="用户名" prop="username">
    <el-input v-model="ruleForm.username"  style="width:300px;"></el-input>
  </el-form-item>
  <el-form-item label="密码" prop="password">
    <el-input v-model="ruleForm.password"  style="width:300px;"></el-input>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="submitForm('ruleForm')">保存</el-button>
    <el-button @click="resetForm('ruleForm')">重置</el-button>
  </el-form-item>
</el-form>
</template>
<script>
  export default {
    data() {
      return {
        ruleForm: {
          username: '',
          password: '',
		  seller_id: this.$route.query.seller_id,
        },
        rules: {
          username: [
            { required: true, message: '请输入用户名', trigger: 'blur' },
            { min: 3, max: 25, message: '长度在 3 到 25 个字符', trigger: 'blur' }
          ],  
		  password: [
		    { required: true, message: '请输入管理员密码', trigger: 'blur' },
		  ]
        }
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.$axios({
				method:"post",
				url:this.host+"/admin/index.php/Seller/saveSellerAdmin",
				data:{
					id : this.$route.query.id,
					seller_id: this.$route.query.seller_id,
					username: this.ruleForm.username,
					password: this.ruleForm.password,
				}
			}).then((res)=>{
				this.$message({
				  message: '保存成功',
				  type: 'success'
				});
				this.$router.push({ path: 'seller-admin' , query:{id:this.ruleForm.seller_id}})
			})
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },
	 
	  getSellerAdmin(){
		this.$axios({
			method:"post",
			url:this.host+"/admin/index.php/Seller/getSellerAdmin",
			data:{
				id : this.$route.query.id
			}
		}).then((res)=>{
			this.ruleForm = res.data 
		})
	  }
    },
	mounted () {
		if(this.$route.query.id)
			this.getSellerAdmin()	
	}
  }
</script>